const app = getApp();
import HttpRequst from '../../utils/httpRequst.js'
import API from '../../utils/config.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollViewH: 0,
    page: 1,
    billType:0,
    pagesize: 20,
    scrollTop: 0,
    isLoading: true,
    isEnding: false,

    filterArr: [{ id: 0, name: "全部" },{ id:2, name: "提现" },{ id:3, name: "佣金" }],
    info:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    
    setTimeout(function(){
      wx.getSystemInfo({
        success: function (res1) {
          const query = wx.createSelectorQuery()
          query.select('#J_sec-header-top').boundingClientRect();
          query.exec(function (res2) {
            that.setData({
              scrollViewH: res1.windowHeight - res2[0].height
            })
            
          });
        }
      });
    },500)
    
    HttpRequst(false, API.capitalList, 1, app.getUkey(), { page: this.data.page, pagesize: this.data.pagesize,type:this.data.billType}, "POST", false, function (res) {
      that.setData({
        info: res.data,
        isLoading: false,
        page: that.data.page + 1,
        isEnding: (res.data.lists.length < that.data.pagesize) ? true : false
      })
    })
  },
  lower: function () {
    if (this.data.isEnding || this.data.isLoading) return;
    var that = this;
    this.setData({
      isLoading: true
    });
    HttpRequst(false, API.capitalList, 1, app.getUkey(), { page: this.data.page, pagesize: this.data.pagesize,type:this.data.billType}, "POST", false, function (res) {
      that.setData({
        ["info.lists"]: that.data.info.lists.concat(res.data.lists),
        isLoading: false,
        page: that.data.page + 1,
        isEnding: (res.data.lists.length < that.data.pagesize) ? true : false
      });
    })
  },

  bindPickerChange(e) {
   
    var that=this;
    this.setData({
      ["info.lists"]:[],
      billType: this.data.filterArr[e.detail.value].id,
      scrollTop:0,
      isLoading: true,
      page: 1,
      isEnding:false
    });
    

    HttpRequst(false, API.capitalList, 1, app.getUkey(), { page: this.data.page, pagesize: this.data.pagesize, type: this.data.filterArr[e.detail.value].id}, "POST", false, function (res) {
      that.setData({
        ["info.lists"]: that.data.info.lists.concat(res.data.lists),
        isLoading: false,
        page: that.data.page + 1,
        isEnding: (res.data.lists.length < that.data.pagesize) ? true : false
      });
    })
  },
  
})